<?php

class RateConfig_5h
{

    public $disk_type = array ( 'a' => "a" , 'b' => "b" , 'c' => "c" , 'd' => "d" );
    public $disk_idx = array ( 'a' => 1 , 'b' => 2 , 'c' => 3 , 'd' => 4 );
    public $xyidArr = array ( "不分盘" , "X 盘" , "X+Y盘" );
    public $xyidTitle = array ( "" , "X盘" , "Y盘" );
    public $splitArr = array ( "全部" , "成数" );
    public $diskArr = array ( "全部" , "a" , "b" , "c" , "d" );
    public $orderArr = array ( "" , "amount" , "number" );
    public $ratemodArr = array ( "目前赔率" , "平均赔率" , "输赢赔率" );
    public $playtypeArr = array ( );
    public $playtypeArr02 = array ( );
    public $playGroupArr = array ( );
    public $playGroupArr02 = array ( );
    public $subArr = array ( );
    public $showAllSubArr = array ( );
    public $showAllSubArr02 = array ( );
    public $showAllBetArr = array ( );
    public $showAllBetArr02 = array ( );
    public $bet4subArr = array ( );
    public $betXYArr = array ( );
    public $tbl;
    public $gametype = 1;
    public $rateFieldStr = "r01,r02,r03,r04,r05,r06,r07,r08,r09,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21";
    public $rateFieldArr = array ( "r01" , "r02" , "r03" , "r04" , "r05" , "r06" , "r07" , "r08" , "r09" , "r10" , "r11" , "r12" , "r13" , "r14" , "r15" , "r16" , "r17" , "r18" , "r19" , "r20" , "r21" );
    public $rcBettypeToN = array ( );
    public $pounNum = 9;
    public $_5hFlag = true;
    public $maxSubId = 0;

    public function RateConfig_5h($gametype = 1)
    {
        global $g_gametype_3d;
        global $g_bet4subArr;
        global $g_betXYArr;
        if ( ! in_array($gametype , array ( 20 , 21 , 22 , 23 , 24 )) )
        {
            exit("error gametype RC5H8H");
        }
        $this->tbl = $g_gametype_3d[$gametype]['en'];
        $this->gametype = $gametype;
        $this->bet4subArr = $g_bet4subArr[$gametype];
        $this->betXYArr = $g_betXYArr[$gametype];
        $this->showAllBetArr02 = array ( "rc" );
        $this->showAllBetArr = array ( "rc" );
        $this->showAllSubArr02 = array ( "rnp" );
        $this->showAllSubArr = array ( "rnp" );
        if ( $gametype == 20 )
        {
            $this->setPlaytypeArr5h();
            $this->_5hFlag = false;
            $this->subArr = array ( 1 => "平码一" , 2 => "平码二" , 3 => "平码三" , 4 => "平码四" , 5 => "特码" );
            $this->maxSubId = 5;
            $this->pounNum = 9;
            $this->rateFieldArr = array ( "r01" , "r02" , "r03" , "r04" , "r05" , "r06" , "r07" , "r08" , "r09" , "r10" , "r11" , "r12" , "r13" , "r14" , "r15" , "r16" , "r17" , "r18" , "r19" , "r20" , "r21" );
        }
        else if ( $gametype == 24 )
        {
            $this->setPlaytypeArr5h();
            $this->_5hFlag = true;
            $this->subArr = array ( 0 => "0" , 1 => "1" , 2 => "2" , 3 => "3" , 4 => "4" , 5 => "5" , 6 => "6" , 7 => "7" , 8 => "8" , 9 => "9" , 10 => "10" );
            $this->maxSubId = 10;
            $this->pounNum = 9;
            $this->rateFieldArr = array ( "r01" , "r02" , "r03" , "r04" , "r05" , "r06" , "r07" , "r08" , "r09" , "r10" , "r11" , "r12" , "r13" , "r14" , "r15" , "r16" , "r17" , "r18" , "r19" , "r20" );
        }
        else
        {
            $this->setPlaytypeArr8h();
            $this->_5hFlag = false;
            $this->subArr = array ( 1 => "第一球" , 2 => "第二球" , 3 => "第三球" , 4 => "第四球" , 5 => "第五球" , 6 => "第六球" , 7 => "第七球" , 8 => "第八球" );
            $this->maxSubId = 8;
            $this->rcBettypeToN = array ( 10 => 2 , 11 => 2 , 12 => 2 , 13 => 3 , 14 => 3 , 15 => 3 , 16 => 4 , 17 => 5 );
            $this->pounNum = 10;
            $this->rateFieldArr = array ( "r01" , "r02" , "r03" , "r04" , "r05" , "r06" , "r07" , "r08" , "r09" , "r10" , "r11" , "r12" , "r13" , "r14" , "r15" , "r16" , "r17" , "r18" , "r19" , "r20" );
        }
    }

    public function setPlaytypeArr5h()
    {
        if ( $this->gametype == 24 )
        {
            $this->playtypeArr = array (
                "r1" => "双面盘" ,
                "rp1" => "冠.亚/和值" ,
                "rp3" => "三.四.五名" ,
                "rp6" => "六.七.八.九.十名",
				"rp7" => "号码盘"
            );
            $this->playGroupArr = array (
                "r1" => array ( "1" , "2" , "3" , "4" , "6" ) ,
                "rp1" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "rp3" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "rp6" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6") ,
                "rp7" => array ( "0") ,
               // "rp9" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" )
            );
            $this->playtypeArr02 = array (
                "r1" => "双面盘" ,
                "rnp" => "1-10位" ,
                "rc" => "冠亚和值"
            );
            $this->playGroupArr02 = array (
                "r1" => array ( 1 , 2 , 3 , 4 , 6 ) ,
                "rnp" => array ( 0 ) ,
                "rc" => array ( 5 )
            );
        }
        else
        {
            $this->playtypeArr = array (
                "r1" => "总合" ,
                "rp1" => "平码1" ,
                "rp2" => "平码2" ,
                "rp3" => "平码3" ,
                "rp4" => "平码4" ,
                "rp5" => "特码" ,
                "r1c1" => "一中一" ,
                "r2c2" => "二中二" ,
                "r3c2" => "三中二" ,
                "r3c3" => "三中三" ,
                "r4c3" => "四中三" ,
                "r5c3" => "五中三" );
            $this->playGroupArr = array (
                "r1" => array ( "7" , "8" , "1" , "2" , "3" , "4" ) ,
                "rp1" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "rp2" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "rp3" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "rp4" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "rp5" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
                "r1c1" => array ( "9" ) ,
                "r2c2" => array ( "10" ) ,
                "r3c2" => array ( "11" ) ,
                "r3c3" => array ( "12" ) ,
                "r4c3" => array ( "13" ) ,
                "r5c3" => array ( "14" ) );
            $this->playtypeArr02 = array (
                "r1" => "双面盘" ,
                "r1clr" => "四喜色波" ,
                "rnp" => "平码1-4．特码" ,
                "rc" => "连码"
            );
            $this->playGroupArr02 = array (
                "r1" => array ( 1 , 2 , 3 , 4 , 7 , 8 ) ,
                "r1clr" => array ( 5 , 6 ) ,
                "rnp" => array ( 0 ) ,
                "rc" => array ( 9 , 10 , 11 , 12 , 13 , 14 )
            );
        }
    }

    public function setPlaytypeArr8h()
    {
        $this->playtypeArr = array (
            "r1" => "两面/龙虎/总和" ,
            "rp1" => "第一球" ,
            "rp2" => "第二球" ,
            "rp3" => "第三球" ,
            "rp4" => "第四球" ,
            "rp5" => "第五球" ,
            "rp6" => "第六球" ,
            "rp7" => "第七球" ,
            "rp8" => "第八球" ,
            "rc" => "连码"
        );
        $this->playGroupArr = array (
            "r1" => array ( "7" , "8" , "9" , "18" , "1" , "2" , "3" , "4" ) ,
            "rp1" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp2" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp3" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp4" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp5" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp6" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp7" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rp8" => array ( "0" , "1" , "2" , "3" , "4" , "5" , "6" ) ,
            "rc" => array ( "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" )
        );
        $this->playtypeArr02 = array (
            "r1" => "双面盘" ,
            "r1clr" => "方位．中发白" ,
            "rnp" => "1-8球" ,
            "rc" => "连码"
        );
        $this->playGroupArr02 = array (
            "r1" => array ( "1" , "2" , "3" , "4" , "7" , "8" , "9" , "18" ) ,
            "r1clr" => array ( "5" , "6" ) ,
            "rnp" => array ( "0" ) ,
            "rc" => array ( "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" )
        );
    }

    public function chkBetSubXyVal($bettype , $subid , $xyidFlag = false , $xyid = -1)
    {
        if ( $this->gametype == 24 && ($bettype == 3 || $bettype == 4) )
        {
            return true;
        }
        if ( in_array($bettype , $this->bet4subArr) )
        {
            $chkSubVal = max(1 , min($this->maxSubId , $subid));
        }
        else
        {
            $chkSubVal = 0;
        }
        if ( $chkSubVal != $subid )
        {
            return false;
        }
        if ( $xyidFlag )
        {
            if ( in_array($bettype , $this->betXYArr) )
            {
                $chkSubVal = max(1 , min(2 , $subid));
            }
            else
            {
                $chkSubVal = 0;
            }
            if ( $chkSubVal != $xyid )
            {
                return false;
            }
            return true;
        }
        return true;
    }

    public function formateRateField($num)
    {
        return "r".str_pad(intval($num) , 2 , "0" , STR_PAD_LEFT);
    }

    public function chkG3G6Idx($bettype)
    {
        return false;
    }

    public function getNumCount($bettype)
    {
        if ( $this->gametype == 20 )
        {
            switch ( $bettype )
            {
                case 9 :
                    return 1;
                case 10 :
                    return 2;
                case 11 :
                    return 3;
                case 12 :
                    return 3;
                case 13 :
                    return 4;
                case 14 :
                    return 5;
            }
            return 1;
        }
        switch ( $bettype )
        {
            case 10 :
                return 2;
            case 11 :
                return 2;
            case 12 :
                return 2;
            case 13 :
                return 3;
            case 14 :
                return 3;
            case 15 :
                return 3;
            case 16 :
                return 4;
            case 17 :
                return 5;
        }
        return 1;
    }

    public function checkDiskType($disk_type)
    {
        return isset($this->disk_type[$disk_type]);
    }

    public function getBetTypeNumber($bettype)
    {
        if ( $this->gametype == 24 )
        {
            switch ( $bettype )
            {
                case 0 :
                    return array ( "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" );
                    break;
                case 1 :
                    return array ( "1" , "2" );
                    break;
                case 2 :
                    return array ( "1" , "2" );
                    break;
                case 3 :
                    return array ( "1" , "2" );
                    break;
                case 4 :
                    return array ( "1" , "2" );
                    break;
                case 5 :
                    return array ("03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" );
                    break;
                case 6 :
                    return array ( "1" , "2" );
                    break;
                default:
                    return array ( );
                    break;
            }
        }
        if ( $this->_5hFlag )
        {
            switch ( $bettype )
            {
                case 0 :
                case 9 :
                case 10 :
                case 11 :
                case 12 :
                case 13 :
                case 14 :
                    return array ( "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" , "20" , "21" );
                case 1 :
                case 2 :
                case 3 :
                case 4 :
                case 7 :
                case 8 :
                    return array ( "1" , "2" );
                case 5 :
                    return array ( "1" , "2" , "3" );
                case 6 :
                    return array ( "1" , "2" , "3" , "4" );
            }
            return array ( );
        }
        switch ( $bettype )
        {
            case 0 :
            case 10 :
            case 11 :
            case 12 :
            case 13 :
            case 14 :
            case 15 :
            case 16 :
            case 17 :
                return array ( "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" , "20" );
            case 1 :
            case 2 :
            case 3 :
            case 4 :
            case 7 :
            case 8 :
            case 9 :
            case 18 :
                return array ( "1" , "2" );
            case 5 :
                return array ( "1" , "2" , "3" );
            case 6 :
                return array ( "1" , "2" , "3" , "4" );
        }
        return array ( );
    }

    public function checkBetNumber($bettype , $num)
    {
        $chkArr = $this->getBetTypeNumber($bettype);
        $arrIdx = array_search($num , $chkArr);
        if ( $arrIdx === false )
        {
            return false;
        }
        return $num === $chkArr[$arrIdx];
    }

    public function getRateFromRateArr($bettype , $num , $rateArr)
    {
        if ( is_array($num) )
        {
            $rateTemp = 9999;
            foreach ( $num as $val )
            {
                $val = intval($val);
                $rateIdx = "r".str_pad($val , 2 , "0" , STR_PAD_LEFT);
                if ( isset($rateArr[$rateIdx]) )
                {
                    $rateTemp = min($rateTemp , floatval($rateArr[$rateIdx]));
                }
                else
                {
                    return 0;
                }
            }
            return 9998 < $rateTemp?0:$rateTemp;
        }
        $num = intval($num);
        $rateIdx = "r".str_pad($num , 2 , "0" , STR_PAD_LEFT);
        if ( isset($rateArr[$rateIdx]) )
        {
            return floatval($rateArr[$rateIdx]);
        }
        return 0;
    }

    public function setRateArrDir($numArr , $addVal)
    {
        $reArr = array ( );
        foreach ( $numArr as $val )
        {
            $numIdx = "r".str_pad(intval($val) , 2 , "0" , STR_PAD_LEFT);
            $reArr[$numIdx] = $addVal;
        }
        return $reArr;
    }

    public function mystr_split($str , $len = 8 , $_5hNumberFlag = false)
    {
        $reArray = array ( );
        if ( 0 < strlen($str) )
        {
            $n = strlen($str) / $len;
            if ( 0 < strlen($str) % $len )
            {
                $n = $n + 1;
            }
            $i = 0;
            while ( $i < $n )
            {
                if ( $_5hNumberFlag )
                {
                    $reArray[] = str_pad(intval(substr($str , $len * $i , $len)) , 2 , "0" , STR_PAD_LEFT);
                }
                else
                {
                    $reArray[] = floatval(substr($str , $len * $i , $len));
                }
                ++ $i;
            }
        }
        return $reArray;
    }

    public function getBetContent($bettype , $num , $smFlag = false)
    {
        //$num = (int)$num;
        switch ( $bettype )
        {
            case 0 :
                return str_pad($num , 2 , "0" , STR_PAD_LEFT);
            case 1 :
                $tempArr = array ( "1" => "单" , "2" => "双" );
                return $tempArr[$num];
            case 2 :
                $tempArr = array ( "1" => "大" , "2" => "小" );
                return $tempArr[$num];
            case 3 :
                if ( $this->gametype == 24 )
                {
                    return $num == "01"?"合单":"合双";
                }
                if ( $smFlag )
                {
                    $tempArr = array ( "1" => "大" , "2" => "小" );
                }
                else
                {
                    $tempArr = array ( "1" => "尾大" , "2" => "尾小" );
                }
                return $tempArr[$num];
            case 4 :
                if ( $this->gametype == 24 )
                {
                    return $num == "01"?"合大":"合小";
                }
                if ( $smFlag )
                {
                    $tempArr = array ( "1" => "单" , "2" => "双" );
                }
                else
                {
                    $tempArr = array ( "1" => "合单" , "2" => "合双" );
                }
                return $tempArr[$num];
            case 5 :
                if ( $this->gametype == 24 )
                {
                    return $num;
                }
                if ( $this->_5hFlag )
                {
                    $tempArr = array ( "1" => "红" , "2" => "蓝" , "3" => "绿" );
                }
                else
                {
                    $tempArr = array ( "1" => "中" , "2" => "发" , "3" => "白" );
                }
                return $tempArr[$num];
            case 6 :
                if ( $this->gametype == 24 )
                {
                    $tempArr = array ( "1" => "龙" , "2" => "虎" );
                }
                else
                {
                    $tempArr = $this->_5hFlag?array ( "1" => "福" , "2" => "禄" , "3" => "寿" , "4" => "喜" ):array ( "1" => "东" , "2" => "南" , "3" => "西" , "4" => "北" );
                }
                return $tempArr[$num];
            case 7 :
                if ( $smFlag )
                {
                    $tempArr = array ( "1" => "单" , "2" => "双" );
                }
                else
                {
                    $tempArr = array ( "1" => "总单" , "2" => "总双" );
                }
                return $tempArr[$num];
            case 8 :
                if ( $smFlag )
                {
                    $tempArr = array ( "1" => "大" , "2" => "小" );
                }
                else
                {
                    $tempArr = array ( "1" => "总大" , "2" => "总小" );
                }
                return $tempArr[$num];
            case 9 :
                if ( $this->_5hFlag )
                {
                    return is_array($num)?implode("," , $num):$num;
                }
                if ( $smFlag )
                {
                    $tempArr = array ( "1" => "大" , "2" => "小" );
                }
                else
                {
                    $tempArr = array ( "1" => "总尾大" , "2" => "总尾小" );
                }
                return $tempArr[$num];
            case 10 :
                return is_array($num)?implode("," , $num):$num;
            case 11 :
                return is_array($num)?implode("," , $num):$num;
            case 12 :
                return is_array($num)?implode("," , $num):$num;
            case 13 :
                return is_array($num)?implode("," , $num):$num;
            case 14 :
                return is_array($num)?implode("," , $num):$num;
            case 15 :
            case 16 :
            case 17 :
                if ( $this->_5hFlag )
                {
                    exit("error 5h bettype");
                }
                else
                {
                    return is_array($num)?implode("," , $num):$num;
                }
                break;
            case 18 :
                if ( $this->_5hFlag )
                {
                    exit("error 5h bettype");
                }
                else
                {
                    $tempArr = array ( "1" => "龙" , "2" => "虎" );
                    return $tempArr[$num];
                }
                break;
            default :
                exit("error bettype");
                break;
        }
        return "";
    }

    public function getPaperOpen()
    {
        return date("Y-m-d");
    }

    public function my_array_fill_keys($keys , $value)
    {
        return array_combine($keys , array_fill(0 , count($keys) , $value));
    }

}

?>